/**
 * @param {string} num
 * @return {string}
 */
var largestGoodInteger = function(num) {
    let resultNum = undefined
    let result = new Set()
    let count = 0
    const arr = num.split('')
    // 遍历一遍，O(n)
    arr.forEach(item => {
        if(resultNum && resultNum === item) {
            count++
            if(count >= 3) result.add(item)
        } else {
            resultNum = item
            count = 1
        }
    })
    const max = result.size ? Math.max(...result) : ''
    return  '' + max + max + max
};

const num = "42352338"
console.log(largestGoodInteger(num))